package com.bgs.eat.shop.controller;

import com.bgs.eat.config.CommonResult;
import com.bgs.eat.page.PageRequest;
import com.bgs.eat.page.PageResult;
import com.bgs.eat.shop.entity.ShopEntity;
import com.bgs.eat.shop.service.ShopService;
import com.bgs.eat.userProtal.entity.UserProtalEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.sql.CommonDataSource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ShopController
 * @Description TODO
 * @Author lzy
 * @Date 2022/10/9 14:53
 **/
@RestController
@CrossOrigin
@RequestMapping("/shop")
public class ShopController {

    @Autowired
    ShopService shopService;

    /**
    * @Description 根据店铺id获取店铺信息（门户用户端）
    * @Author lzy
    * @Date 2022/10/28 8:58
    * @Return com.bgs.eat.config.CommonResult
    * @param id
    */
    @GetMapping("/getShopFormById")
    public CommonResult getShopFormById(Integer id){
        return shopService.getShopFormById(id);
    }

    /**
    * @Description 店铺展示（门户展示）
    * @Author lzy
    * @Date 2022/10/10 16:47
    * @Return com.bgs.eat.config.CommonResult

    */
    public CommonResult dd(){
        return null;
    }

    /**
    * @Description 新增店铺（门户展示 店家申请个开通店铺）
    * @Author lzy
    * @Date 2022/10/16 20:38
    * @Return com.bgs.eat.config.CommonResult
    * @param shopEntity
    */
    @PostMapping("/saveShop")
    public CommonResult saveShop(@RequestBody ShopEntity shopEntity){
        return shopService.saveShop(shopEntity);
    }

    /**
    * @Description 申请店铺 上传相关图片
    * @Author lzy
    * @Date 2022/10/13 19:14
    * @Return com.bgs.eat.config.CommonResult
    * @param file
    * @param name
    */
    @RequestMapping("/applyUploadImage")
    public CommonResult applyUploadImage(MultipartFile file,String name){
        return shopService.applyUploadImage(file,name);
    }

    /**
    * @Description 根据用户id获取 名下所有店铺（门户商家版 展示）
    * @Author lzy
    * @Date 2022/10/18 9:04
    * @Return com.bgs.eat.config.CommonResult
    * @param userId
    */
    @GetMapping("/getShopListByUserId")
    public CommonResult getShopListByUserId(Integer userId) {
        return shopService.getShopListByUserId(userId);
    }

    /**
    * @Description 修改店铺营业状态（门户商家版 展示）
    * @Author lzy
    * @Date 2022/10/18 14:36
    * @Return com.bgs.eat.config.CommonResult
    * @param status
    */
    @GetMapping("/editShopStatus")
    public CommonResult editShopStatus(Integer status, Integer shopId) {
        return shopService.editShopStatus(status, shopId);
    }

    /**
    * @Description 根据 店铺id获取店铺信息（门户商家版）
    * @Author lzy
    * @Date 2022/10/19 9:03
    * @Return com.bgs.eat.config.CommonResult
    * @param shopId
    */
    @GetMapping("/shopById")
    public CommonResult shopById(Integer shopId) {
        return shopService.shopById(shopId);
    }


    /**
    * @Author hbx
    * @Description 全查店铺信息
    * @Date 2022/10/20 9:41

    */
    @GetMapping("/getAllShop")
    public CommonResult getAllShop(){
        return CommonResult.ok(shopService.getAllShop());
    }

    /**
    * @Author cjl
    * @Description 后台 店铺管理 全查（模糊查店铺名字）
    * @Date  11:29
    * @Return com.bgs.eat.config.CommonResult
    * @param shopName
    */
    @GetMapping("/getAllShopEntityByShopName")
    PageResult getAllShopEntityByShopName(String shopName,String roleId,String countyId,PageRequest pageRequest){
        PageResult pageResult = shopService.getAllShopEntityByShopName(shopName,roleId,countyId,pageRequest);
        return pageResult;
    }

    /**
    * @Author cjl
    * @Description 后台 下架店铺 删除标识变为 0  关闭店铺理由
    * @Date  8:26
    * @Return com.bgs.eat.config.CommonResult
    * @param shopEntity
    */
    @PutMapping("/updateShopEntityByDelFlagOne")
    CommonResult updateShopEntityByDelFlag(ShopEntity shopEntity){
        int i = shopService.updateShopEntityByDelFlag(shopEntity);
        return CommonResult.ok(i);
    }

    /**
    * @Author cjl
    * @Description 后台 回复店铺全查
    * @Date  8:27
    * @Return com.bgs.eat.page.PageResult
    * @param shopName
    * @param pageRequest
    */
    @GetMapping("/getAllShopEntityDelFlagZero")
    PageResult getAllShopEntityDelFlagZero(String shopName,String roleId,String countyId,PageRequest pageRequest){
        PageResult pageResult = shopService.getAllShopEntityDelFlagZero(shopName,roleId,countyId,pageRequest);
        return pageResult;
    }
    /**
    * @Author cjl
    * @Description 后台 上架商铺
    * @Date  8:28
    * @Return com.bgs.eat.config.CommonResult
    * @param shopEntity
    */
    @PutMapping("/updateShopEntityByDelFlagZero")
    CommonResult updateShopEntityByDelFlagZero(ShopEntity shopEntity){
        int i = shopService.updateShopEntityByDelFlagZero(shopEntity);
        return CommonResult.ok(i);
    }


    /**
    * @Author cjl
    * @Description 审批店铺管理全查 根据地区展示店铺（后端）
    * @Date  9:53
    * @Return com.bgs.eat.page.PageResult
    * @param shopName
    * @param roleId
    * @param countyId
    * @param pageRequest
    */
    @GetMapping("/selectShopLeftJoinUserProtal")
    PageResult selectShopLeftJoinUserProtal(String shopName,Integer roleId,Integer countyId,PageRequest pageRequest){
        PageResult pageResult = shopService.selectShopLeftJoinUserProtal(shopName,roleId,countyId,pageRequest);
        return pageResult;
    }
    /**
    * @Author cjl
    * @Description 审批店铺通过（后端）
    * @Date  11:31
    * @Return com.bgs.eat.config.CommonResult
    * @param shopEntity
    */
    @PutMapping("/examineShopSucceed")
    CommonResult examineShopSucceed (ShopEntity shopEntity){
        int i = shopService.examineShopSucceed(shopEntity);
        return CommonResult.ok();
    }

    /**
    * @Author cjl
    * @Description 审批店铺失败（后端）
    * @Date  8:29
    * @Return com.bgs.eat.config.CommonResult
    * @param map
    */
    @PutMapping("/examineShopFailed")
    CommonResult examineShopFailed (@RequestBody Map<String,String> map){
        int i = shopService.examineShopFailed(map);
        return CommonResult.ok();
    }


    /**
    * @Author G胖
    * @Description 修改商户版店铺信息
    * @Date 2022-10-26 下午 01:50
    * @Return com.bgs.eat.config.CommonResult

    */
    @PostMapping("/editShop")
    public CommonResult editShop(@RequestBody ShopEntity shopEntity){
        return CommonResult.ok(shopService.editShop(shopEntity));
    }

    /**
    * @Author G胖
    * @Description 修改门脸照id
    * @Date 2022-10-26 下午 03:23
    * @Return

    */
    @PostMapping("/updateFacadeImageId")
    public CommonResult updateFacadeImageId(@RequestBody ShopEntity shopEntity){
        return CommonResult.ok(shopService.updateFacadeImageId(shopEntity));
    }

    /**
    * @Author G胖
    * @Description 修改店内照id
    * @Date 2022-10-26 下午 03:48
    * @Return

    */
    @PostMapping("/updatelobbyImageId")
    public CommonResult updatelobbyImageId(@RequestBody ShopEntity shopEntity){
        return CommonResult.ok(shopService.updatelobbyImageId(shopEntity));
    }

    /**
    * @Author G胖
    * @Description 修改商店logo
    * @Date 2022-10-26 下午 03:57
    * @Return com.bgs.eat.config.CommonResult

    */
    @PostMapping("/updateShopLogo")
    public CommonResult updateShopLogo(@RequestBody ShopEntity shopEntity){
        return CommonResult.ok(shopService.updateShopLogo(shopEntity));
    }

}
